<template>
  <div class="posting">
    <div class="headera">
      <div class="img">
        <img src="../assets/img/fanhui.png" alt="" />
      </div>
      <div class="title" @click="goes">发帖</div>
    </div>
    <div class="main">
      <ul>
        <li>
          <span>标题</span>
          <input type="text" placeholder="必填"  v-model="title"/>
        </li>
        <li class="big">
          <input type="text" placeholder="想和大家分享点什么..." v-model="content"/>
          <div class="file">
            <van-uploader v-model="fileList" multiple />
          </div>
        </li>
      </ul>

      <div class="gos" @click="upload">
        发表
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      title:'',
      content:'',
      fileList: [
        // { url: 'https://img01.yzcdn.cn/vant/leaf.jpg' },
        // Uploader 根据文件后缀来判断是否为图片文件
        // 如果图片 URL 中不包含类型信息，可以添加 isImage 标记来声明
      ],
      // id:10,
      // uploadList:[]
      uploadList:
        {
          title:'',
          content:'',
          fileList:[{url:''}],
          id:null
        }
      ,
    };
  },
  methods:{
    upload(){
      this.id+=1;
      window.localStorage.setItem("ids",this.id);
      // this.uploadList.push(this.title);
      this.uploadList.title = this.title;
      this.uploadList.content = this.content;
      this.uploadList.fileList = this.fileList;
      this.uploadList.id = this.id;
      console.log(window.localStorage.ids);
      
      this.$emit("upload",{uploadList:this.uploadList});
      this.$toast("发表成功");
      this.$router.go(-1);
      console.log(window.localStorage.ids);
      console.log(this.uploadList);
    },
    goes(){
      this.$router.go(-1);
    }
  },
  mounted(){
    // window.localStorage.ids+=1;
    this.id = Number(window.localStorage.getItem("ids"));
    console.log(this.id,typeof(this.id));
  },
};
</script>

<style lang="scss" scoped>
.posting {
  .headera {
    display: flex;
    justify-content: flex-start;
    padding: 10px;
    background: #53bcf5;
    height: 63px;
    box-sizing: border-box;
    border-bottom: 15px solid #f3f3f3;
    .img {
      width: 20px;
      height: 20px;
      margin-top: 4px;
      img {
        width: 100%;
      }
    }
    .title {
      font-size: 18px;
      font-weight: 400;
      color: #fff;
      flex: 1;
      text-align: center;
    }
  }
  .main{
    ul{
      li{
        height: 43px;
        line-height: 43px;
        display: flex;
        border-bottom:1px solid #f6f6f6;
        font-size: 15px;
        padding: 0 12px;
        span{
          color: #cacbca;
        }
        input{
          border: none;
          flex: 1;
          padding-left: 15px;
        }
      }
      .big{
        position: relative;
        height: 188px;
        input{
          width: 100%;
          padding-bottom: 140px;
          }
          .file{
            position: absolute;
            bottom: 34px;
            left: 12px;
            width: 60px;
            height: 60px;
            ::v-deep .van-uploader__wrapper{
              flex-wrap: nowrap;
              -webkit-flex-wrap: revert;
            }
          }
       
      }
    }
  }
  .gos{
    margin: 75px 16px 0 16px;
    background: #99db5e;
    height: 44px;
    line-height: 44px;
    text-align: center;
    font-size: 17px;
    color: #fff;
    border-radius: 6px;
  }
}
</style>
